package com.yanchangapp.ui.presenter;

import com.yanchangapp.base.HeadApiRetrofit;
import com.yanchangapp.commom.AppConstant;
import com.yanchangapp.model.bean.GoodsApplyBean;
import com.yanchangapp.ui.view.GoodsDetailAtView;
import com.zxl.baselib.bean.response.BaseResponse;
import com.zxl.baselib.ui.base.BaseActivity;
import com.zxl.baselib.ui.base.BaseObserver;
import com.zxl.baselib.ui.base.BasePresenter;
import com.zxl.baselib.ui.base.ExceptionHandle;

import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.schedulers.Schedulers;

/**
 * Created by apple on 2019-08-22.
 * description:
 */
public class GoodsDetailAtPresenter extends BasePresenter<GoodsDetailAtView> {


    public GoodsDetailAtPresenter(BaseActivity context) {
        super(context);
    }

    public void queryGoodsDetail(String productId,int isThirdFlag){
        HeadApiRetrofit.getInstance().queryApplyDetail(productId,isThirdFlag)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new BaseObserver<BaseResponse<GoodsApplyBean>>() {
                    @Override
                    public void onNext(BaseResponse<GoodsApplyBean> goodsApplyBeanBaseResponse) {
                        if (getView() != null){
                            if (AppConstant.REQUEST_SUCCESS == goodsApplyBeanBaseResponse.getCode()){
                                getView().queryGoodsDetailSuccess(goodsApplyBeanBaseResponse.getData());
                            }else {
                                getView().queryGoodsDetailFailure(goodsApplyBeanBaseResponse.getMsg());
                            }
                        }
                    }

                    @Override
                    public void onError(ExceptionHandle.ResponseException exception) {
                        if (getView() != null){
                            getView().queryGoodsDetailFailure(exception.getErrorInfo());
                        }
                    }
                });
    }
}
